package response;


import com.baidu.unbiz.fluentvalidator.ComplexResult;
import com.baidu.unbiz.fluentvalidator.ValidationError;

/**
 * 功能:
 * 作者: 洪世成
 * 日期: 2017/9/10
 * 版权所有: admin
 */
public class CommonResult  {


    private int status=0;
    private StringBuffer message = new StringBuffer();
    private Object data;


    public static CommonResult newCommonResult() {
        CommonResult commonResult = new CommonResult();
        return commonResult;
    }

    public CommonResult setSuccess() {
        this.setStatus(1);
        return this;
    }

    public CommonResult setError() {
        this.setStatus(0);
        return this;
    }

    public void addMessage(String message) {
        this.message.append("<p>");
        this.message.append(message);
        this.message.append("</p>");
    }

    public void addMessage(ComplexResult complexResult) {
        for( ValidationError error: complexResult.getErrors())
         addMessage(error.getErrorMsg());
    }

    public String getMessage() {
        return message.toString();
    }

    public void setMessage(String message) {
        this.message=new StringBuffer();
        addMessage(message);
    }
    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }
}
